package com.ming.controller;

import com.ming.po.ResponseBean;
import com.ming.po.User;
import com.ming.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/UserController")
public class UserController {

	@Autowired
	private UserService us;

	@PostMapping("/getUserByIdByPass")
	public ResponseBean<User> getUserByIdByPass(User user, HttpSession hs){
		ResponseBean<User> result = us.getUserByIdByPass(user);
		if(user!=null){
			hs.setAttribute("user",user);
			// 超时时间设置,此处设为60秒
			hs.setMaxInactiveInterval(60);
		}
		return result;
	}

	@PostMapping("/getUserById")
	public ResponseBean<User> getUserById(String userId){
		return us.getUserById(userId);
	}

	@PostMapping("/saveUser")
	public ResponseBean<Integer> saveUser(User user){
		return us.saveUser(user);
	}

	@PostMapping("/updateUserImg")
	public ResponseBean<Integer> updateUserImg(User user){
		return us.updateUserImg(user);
	}

	@PostMapping("/logOut")
	public String logOut(HttpSession hs){
		// 销毁session
		hs.invalidate();
		return "not log";
	}

	@PostMapping("/updatePwd")
	public ResponseBean<Integer> updatePwd(User user){
		return us.updatePwd(user);
	}

	@PostMapping("/isSameOldPwd")
	public ResponseBean<Integer> isSameOldPwd(User user){
		return us.isSameOldPwd(user);
	}
}
